home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / sprite.X11R3 / RCS / spriteIo.c,v < prev    next >
Encoding:
Text File  |  1989-10-13  |  6.8 KB  |  306 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     88.03.27.21.17.12;  author deboor;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     87.06.20.19.56.44;  author deboor;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     87.06.16.12.21.00;  author deboor;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @Main I/O controller functions
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @*** empty log message ***
  33. @
  34. text
  35. @/*-
  36.  * spriteIo.c --
  37.  *    Functions to handle input from the keyboard and mouse.
  38.  *
  39.  * Copyright (c) 1987 by the Regents of the University of California
  40.  *
  41.  * Permission to use, copy, modify, and distribute this
  42.  * software and its documentation for any purpose and without
  43.  * fee is hereby granted, provided that the above copyright
  44.  * notice appear in all copies.  The University of California
  45.  * makes no representations about the suitability of this
  46.  * software for any purpose.  It is provided "as is" without
  47.  * express or implied warranty.
  48.  *
  49.  *
  50.  */
  51. #ifndef lint
  52. static char rcsid[] =
  53.     "$Header: spriteIo.c,v 1.2 87/06/20 19:56:44 deboor Exp $ SPRITE (Berkeley)";
  54. #endif lint
  55.  
  56. #include    "spriteddx.h"
  57.  
  58.  
  59. Bool              screenSaved = FALSE;
  60. /*
  61.  * lastEventTime is used by the OS layer to decide when to do the screen
  62.  * saver stuff. lastEventTimeMS is used by the cursor module when it generates
  63.  * motion events in spriteSetCursorPosition. This is necessary because on
  64.  * sun2's, the time in the keyboard events is relative to boot time, while
  65.  * on sun3's it's real time, so what can you do?
  66.  */
  67. unsigned int         lastEventTime = 0;
  68. unsigned int      lastEventTimeMS = 0;
  69.  
  70. int              spriteCheckInput = 0;
  71. #define RESTORE_CURSOR    0x01
  72. #define READ_INPUT    0x02
  73.  
  74. /*-
  75.  *-----------------------------------------------------------------------
  76.  * spriteCursorGone --
  77.  *    This is a function required by the cursor code which is
  78.  *    just like spriteInputAvail, except it marks that the cursor
  79.  *    needs to be restored.
  80.  *
  81.  * Results:
  82.  *    None.
  83.  *
  84.  * Side Effects:
  85.  *    spriteCheckInput is altered to contain the RESTORE_CURSOR flag.
  86.  *
  87.  *-----------------------------------------------------------------------
  88.  */
  89. void
  90. spriteCursorGone()
  91. {
  92.     spriteCheckInput |= RESTORE_CURSOR;
  93. }
  94.  
  95. /*-
  96.  *-----------------------------------------------------------------------
  97.  * spriteInputAvail --
  98.  *    This function is called from the scheduler whenever one of
  99.  *    the devices we told it to look for has input waiting.
  100.  *
  101.  * Results:
  102.  *    None.
  103.  *
  104.  * Side Effects:
  105.  *    spriteCheckInput has its READ_INPUT flag set.
  106.  *
  107.  *-----------------------------------------------------------------------
  108.  */
  109. void
  110. spriteInputAvail()
  111. {
  112.     spriteCheckInput |= READ_INPUT;
  113. }
  114.  
  115. /*-
  116.  *-----------------------------------------------------------------------
  117.  * SetTimeSinceLastInputEvent --
  118.  *    Set the lastEventTime to now.
  119.  *
  120.  * Results:
  121.  *    None.
  122.  *
  123.  * Side Effects:
  124.  *    lastEventTime is altered.
  125.  *
  126.  *-----------------------------------------------------------------------
  127.  */
  128. void
  129. SetTimeSinceLastInputEvent()
  130. {
  131.     SpriteTime      now;
  132.  
  133.     Sys_GetTimeOfDay (&now, (int *)0, (Boolean *)0);
  134.     lastEventTime = TVTOMILLI(now);
  135. }
  136.  
  137. /*-
  138.  *-----------------------------------------------------------------------
  139.  * TimeSinceLastInputEvent --
  140.  *    Function used for screensaver purposes by the os module.
  141.  *
  142.  * Results:
  143.  *    The time in milliseconds since there last was any
  144.  *    input.
  145.  *
  146.  * Side Effects:
  147.  *    None.
  148.  *
  149.  *-----------------------------------------------------------------------
  150.  */
  151. int
  152. TimeSinceLastInputEvent()
  153. {
  154.     SpriteTime      now;
  155.  
  156.     Sys_GetTimeOfDay(&now, (int *)NULL, (Boolean *)NULL);
  157.  
  158.     if (lastEventTime == 0) {
  159.     lastEventTime = TVTOMILLI(now);
  160.     }
  161.     return TVTOMILLI(now) - lastEventTime;
  162. }
  163.  
  164. /*-
  165.  *-----------------------------------------------------------------------
  166.  * ProcessInputEvents --
  167.  *    Retrieve all waiting input events and pass them to DIX in their
  168.  *    correct chronological order. The keyboard driver is responsible
  169.  *    for reading all the events (both for the mouse and the keyboard).
  170.  *
  171.  * Results:
  172.  *    None.
  173.  *
  174.  * Side Effects:
  175.  *    Events are passed to the DIX layer.
  176.  *
  177.  *-----------------------------------------------------------------------
  178.  */
  179. void
  180. ProcessInputEvents ()
  181. {
  182.     register Dev_KbdEvent  *events;         /* Array of events */
  183.     register int          numEvents;        /* Number of events left */
  184.     int                      nE;                /* Total number of events */
  185.     DevicePtr            pPointer;        /* System pointer */
  186.     DevicePtr            pKeyboard;        /* System keyboard */
  187.     register PtrPrivPtr     ptrPriv;        /* Private data for pointer */
  188.     register KbPrivPtr        kbdPriv;        /* Private data for keyboard */
  189.     Dev_KbdEvent          *lastEvent;        /* Last event processed */
  190.     enum {
  191.     NoneYet, Ptr, Kbd
  192.     }                lastType = NoneYet;    /* Type of last event */
  193.  
  194.     if (spriteCheckInput & READ_INPUT) {
  195.     pPointer = LookupPointerDevice();
  196.     pKeyboard = LookupKeyboardDevice();
  197.     
  198.     ptrPriv = (PtrPrivPtr)pPointer->devicePrivate;
  199.     kbdPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  200.     
  201.     /*
  202.      * Get events from both the pointer and the keyboard via the keyboard's
  203.      * GetEvents vector. The number of events read is stored in numEvents.
  204.      */
  205.     events = (* kbdPriv->GetEvents) (pKeyboard, &nE);
  206.     numEvents = nE;
  207.     
  208.     while (numEvents) {
  209.         if (events->device == DEV_KBD_KEY) {
  210.         if (lastType == Ptr) {
  211.             (* ptrPriv->DoneEvents) (pPointer, FALSE);
  212.             lastType = Kbd;
  213.         }
  214.         (* kbdPriv->ProcessEvent) (pKeyboard, events);
  215.         } else if (events->device == DEV_KBD_MOUSE) {
  216.         if (lastType == Kbd) {
  217.             (* kbdPriv->DoneEvents) (pKeyboard, FALSE);
  218.             lastType = Ptr;
  219.         }
  220.         (* ptrPriv->ProcessEvent) (pPointer, events);
  221.         } else {
  222.         /* ??? */
  223.         }
  224.         lastEvent = events;
  225.         lastEventTimeMS = events->time;
  226.         numEvents -= 1;
  227.         events += 1;
  228.     }
  229.     
  230.     SetTimeSinceLastInputEvent();
  231.     if (screenSaved) {
  232.         SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverReset);
  233.     }
  234.     
  235.     (* kbdPriv->DoneEvents) (pKeyboard, TRUE);
  236.     (* ptrPriv->DoneEvents) (pPointer, TRUE);
  237.     }
  238.  
  239.  
  240.     if (spriteCheckInput & RESTORE_CURSOR) {
  241.     spriteRestoreCursor();
  242.     }
  243.     spriteCheckInput = 0;
  244. }
  245. @
  246.  
  247.  
  248. 1.2
  249. log
  250. @adapted to Beta-0
  251. @
  252. text
  253. @d19 1
  254. a19 1
  255.     "$Header: spriteIo.c,v 1.1 87/06/16 12:21:00 deboor Exp $ SPRITE (Berkeley)";
  256. d26 9
  257. a34 1
  258. int              lastEventTime = 0;
  259. d51 1
  260. a51 1
  261.  *    spriteCheckInput is bumped
  262. d191 1
  263. @
  264.  
  265.  
  266. 1.1
  267. log
  268. @Initial revision
  269. @
  270. text
  271. @d19 1
  272. a19 1
  273.     "$Header: spriteIo.c,v 2.7 87/05/13 15:06:53 deboor Exp $ SPRITE (Berkeley)";
  274. d34 2
  275. a35 2
  276.  * sunInputAvail --
  277.  *    This is a function required by the sunCursor code which is
  278. d48 1
  279. a48 1
  280. sunInputAvail()
  281. d196 1
  282. d198 1
  283. a198 1
  284.     sunRestoreCursor();
  285. a200 19
  286. }
  287.  
  288. /*-
  289.  *-----------------------------------------------------------------------
  290.  * sunUseSunWindows --
  291.  *    Fake function to allow use of sunCursor.c    
  292.  *
  293.  * Results:
  294.  *    FALSE.
  295.  *
  296.  * Side Effects:
  297.  *    None.
  298.  *
  299.  *-----------------------------------------------------------------------
  300.  */
  301. Boolean
  302. sunUseSunWindows()
  303. {
  304.     return FALSE;
  305. @
  306.